<%@ page contentType="text/html;charset=UTF-8" %>
<%@ include file="/WEB-INF/views/include/taglib.jsp"%>
<html>
<head>
	<title>疫苗固有信息管理</title>
	<meta name="decorator" content="default"/>
	<script type="text/javascript">
		$(document).ready(function() {
			//$("#name").focus();
			$("#inputForm").validate({
				submitHandler: function(form){
					loading('正在提交，请稍等...');
					form.submit();
				},
				errorContainer: "#messageBox",
				errorPlacement: function(error, element) {
					$("#messageBox").text("输入有误，请先更正。");
					if (element.is(":checkbox")||element.is(":radio")||element.parent().is(".input-append")){
						error.appendTo(element.parent().parent());
					} else {
						error.insertAfter(element);
					}
				}
			});
			initVaccName();
			initCompanyName();
		});
		function initVaccName(name){
			var select='<option value="请选择">--请选择--</option>';
			var url = "${ctx}/vaccinate/bsVaccine/getVaccineName";
			$.ajax({
				url : url,	
				success : function(data){
					data=$.parseJSON(data);  
					var html = "";
						for(var i=0;i<data.length;i++){
							select+="<option value='"+data[i].id+"'>"+data[i].name+"</option>";
						};
					$("#vaccineName").append(select);
					if(name){
						$("#vaccineName").removeAttr('onchange');
						$("#vaccineName").val(name).trigger("change");
						$("#vaccineName").attr('onchange','getCompany();');
					} 
				}
			});
		}
		function initCompanyName(company){
				var select='<option value="请选择">--请选择--</option>';
				var url = "${ctx}/company/bsCompany/getCompany";
				$.ajax({
					url : url,	
					success : function(data){
						data=$.parseJSON(data);  
						var html = "";
							for(var i=0;i<data.length;i++){
								select+="<option value='"+data[i].code+"'>"+data[i].name+"</option>";
							};
						$("#companyName").append(select);
						if(company){
							$("#companyName").removeAttr('onchange');
							$("#companyName").val(company).trigger("change");
							$("#companyName").attr('onchange','getVacc();');
						} 
					}
				});
			
		}
		function getCompany(){//根据疫苗ID获取生产企业
			var str=$("#vaccineName").val();
			var com=$("#companyName").val();
			if(str=='请选择'){
				$("#companyName").find("option").remove(); 
				$("#companyName").select2();
				initCompanyName(com);
				return ;
			}
			if(com!="请选择"){
				get(1);
				return;
			}
			var url = "${ctx}/vaccinate/bsVaccineInfo/getCompanyInfo";
			var select='<option value="请选择">--请选择--</option>';
			$("#companyName").find("option").remove(); 
			$("#companyName").select2();
			$.ajax({
				url:url,
				data:{"id":$("#vaccineName").val()},
				success:function(data){
						data=$.parseJSON(data); 
						for(var i=0;i<data.length;i++){
							select += "<option value='"+data[i].companyCode+"'>" + data[i].companyName + "</option>";
						}
						$("#companyName").append(select);
						$("#companyName").removeAttr('onchange');
						$("#companyName").val(com).trigger("change");
						$("#companyName").attr('onchange','getVacc();');
					}
			});
		}
		function getVacc(){//获取疫苗信息
			var str=$("#companyName").val();
			var com=$("#vaccineName").val();
			if(str=='请选择'){//生产企业选择为空，对疫苗初始化操作
				$("#vaccineName").find("option").remove(); 
				$("#vaccineName").select2();
				initVaccName(com);
				return ;
			}
			if(com!="请选择"){
				get(2);
				return;
			}else{
				var url = "${ctx}//vaccinate/bsVaccineInfo/getVaccineInfo";
				var select='<option value="请选择">--请选择--</option>';
				var vname=$("#vaccineName").val();
				$("#vaccineName").find("option").remove(); 
				$("#vaccineName").select2();
				$.ajax({
					url:url,
					data:{"id":$("#companyName").val()},
					success:function(data){
							data=$.parseJSON(data); 
							for(var i=0;i<data.length;i++){
								select+="<option value='"+data[i].vaccineId+"'>"+data[i].vaccineName+"</option>";
							}
							$("#vaccineName").append(select);
							$("#vaccineName").removeAttr('onchange');
							$("#vaccineName").val(vname).trigger("change");
							$("#vaccineName").attr('onchange','getCompany();');
					}
				});
				
			}

		}
		
		//获得疫苗基本信息
		function get(num){
		if(num==1){
			var url = "${ctx}/vaccinate/bsVaccineInfo/getCompanyInfo";
			var select='<option value="请选择">--请选择--</option>';
			var vname=$("#companyName").val();
			$("#companyName").find("option").remove(); 
			$("#companyName").select2();
			$.ajax({
				url:url,
				data:{"id":$("#vaccineName").val()},
				success:function(data){
						data=$.parseJSON(data); 
						for(var i=0;i<data.length;i++){
							select += "<option value='"+data[i].companyCode+"'>" + data[i].companyName + "</option>";
						}
					$("#companyName").append(select);
					$("#companyName").removeAttr('onchange');
					$("#companyName").val(vname).trigger("change");
					$("#companyName").attr('onchange','getVacc();');
					open();
					}
			});
		}
		if(num==2){//疫苗选项不为请选择
			var url = "${ctx}//vaccinate/bsVaccineInfo/getVaccineInfo";
			var select='<option value="请选择">--请选择--</option>';
			var vname=$("#vaccineName").val();
			$("#vaccineName").find("option").remove(); 
			$("#vaccineName").select2();
			$.ajax({
				url:url,
				data:{"id":$("#companyName").val()},
				success:function(data){
						data=$.parseJSON(data); 
						for(var i=0;i<data.length;i++){
							select+="<option value='"+data[i].vaccineId+"'>"+data[i].vaccineName+"</option>";
						}
						$("#vaccineName").append(select);
						$("#vaccineName").removeAttr('onchange');
						$("#vaccineName").val(vname).trigger("change");
						$("#vaccineName").attr('onchange','getCompany();');
						open();
				}
			});
			
		}
// 		 $("div[data-line=line1]").find("span[data=add]").text("正在查询中...");
// 		 var height = window.screen.height - 600;
// 		 var width = window.screen.width -800;
// 		 var vaccineId= $("#vaccineName").val();
// 		 var companyCode = $("#companyName").val();
// 		 var  url = "${ctx}/vaccinate/bsVaccineInfo/getList?vaccineId="+vaccineId+"&companyCode="+companyCode;
// 		    layer.open({
// 		        type: 2,
// 		        title: '',
// 		        shadeClose: true,
// 		        skin: 'layui-layer-rim',
// 		        shade: 0.8,
// 		        closeBtn:true,
// 		        resize:false,
// 		        area: [width+"px", height+"px"],
// 		        content: url
// 		      });
		    //$("div[data-line=line1]").find("span[data=add]").text("已查询...");
		 
		}
		
		function open(){
			 $("div[data-line=line1]").find("span[data=add]").text("正在查询中...");
	 		 var height = window.screen.height - 600;
	 		 var width = window.screen.width -800;
	 		 var vaccineId= $("#vaccineName").val();
	 		 var companyCode = $("#companyName").val();
	 		 var  url = "${ctx}/vaccinate/bsVaccineInfo/getList?vaccineId="+vaccineId+"&companyCode="+companyCode;
	 		    layer.open({
	 		        type: 2,
	 		        title: '',
	 		        shadeClose: true,
	 		        skin: 'layui-layer-rim',
	 		        shade: 0.8,
	 		        closeBtn:true,
	 		        resize:false,
	 		        area: [width+"px", height+"px"],
	 		        content: url
	 		      });
			
		}
		
		
		function closeIframe(){
			var index = parent.layer.getFrameIndex(window.name);
			if(index){
				parent.layer.close(index);
			}else{
				window.location.href = "${ctx}/vaccinate/bsVaccineBatchno/manageBatchno?batchType=1";
			}
		}
		
		function addInfo(info){
			debugger;
			$("#vid").val(info.id);
			$("#spec").val(info.spec);
			$("#doseType").val(info.doseType1);
			$("#largePackage").val(info.largePackage);
			$("#dose").val(info.dose);
			$("#containerTypeName").val(info.containerTypeNam1);
			$("#customBillNo").val(info.customBillNo);
			$("div[data-line=line1]").find("span[data=add]").text("已查询");
		}
		
		function rese(){
			
			var selects = $("select");
			
			for(var i=0;i<selects.length;i++){
				selects[i].options[0].selected = true; 

			}
			location.reload();
		}
		
		function checkBatchno(){
			var url = "${ctx}/vaccinate/bsVaccineBatchno/checkBatchno";
			$.ajax({
				url :url,
				data :{"batchno":$("#batchno").val()} ,
				success : function(data){
					if(data.length>0){
						$("#ll").text("该批次已存在!");
					}else{
						$("#ll").text("");
					}
				}
			});
		}
		function check(thi){
			var str =$(thi).val();
			if($("#batchno").val()==""){
				$("#ll").text("请输入批号!");
			}else{
				$("#ll").text("");
			}
			
			if(str != $("#batchno").val()){
				$("#la").text("请重新输入!");
			}else{
				$("#la").text("");
			}
		}
		function save(){
			if($("#batchno").valid()&&$("#batchno1").valid()&&$("#outBoundDate").valid()){
				if($("#batchno1").val()&&$("#batchno").val()){
					$.ajax({
						url : "${ctx}/vaccinate/bsVaccineBatchno/saveBatchno",
						data :{"vid": $("#id").val(), 
							   "batchno" : $("#batchno").val(),
							   "code"   : $("#code").val(),
							   "secondBatchno" : $("#batchno1").val(),
							   "certifiCode" : $("#certifiCode").val(),
							   "outBoundDate" : $("#outBoundDate").val(),
							   "entrance" : $("#isYes").val(),
							   "vaccineId" : $("#vaccineName").val(),
							   "companyCode" : $("#companyName").val(),
							   "batchType":'${batchType}',
							   "inoculation":$("#inoculation").val()
						},
						success: function(data){
							if(data){
								layer.msg("保存成功!");
									setTimeout('closeIframe()',2000);
							}
						}
					});
				}
			}
			
		}
	</script>
	
	<style type="text/css">
		body{
			padding:20px;
		}
		.minWidth {
			min-width: 500px;
		}
		
		@media ( min-width : 789px) and (max-width: 1098px) {
			.secondChild {
				margin-left: 0
			}
		}
		[class*="span"] {
			margin-left: 0px;
		}
	</style>
</head>
<body>
	<ul class="nav nav-tabs">
		
	</ul><br/>
	<form id="inputForm"  action="${ctx}/vaccinate/bsVaccineInfo/save" method="post" class="form-horizontal">
		<input type="hidden" id="id"/>
		<sys:message content="${message}"/>
	<div class="container-fluid">

	<div class="row-fluid">
		<div class="control-group span6 minWidth" data-line="line1">
			<label class="control-label">疫苗名称：</label>
			<div class="controls">
			<select id="vaccineName" name="vaccineName" class="span7" onchange="getCompany()">
			</select>
			<span class="help-inline" data="add"></span>
			</div>
		</div>
		
		<div class="control-group span6 minWidth" data-line="line2">
			<label class="control-label">生产企业：</label>
			<div class="controls">
			<select id="companyName" name="companyName" class="span7" onchange="getVacc()">
			</select>
			</div>
		</div>
	</div>	

	<div class="row-fluid">
		<div class="control-group span6 minWidth">
			<label class="control-label">规格：</label>
			<div class="controls">
				
				<input type="text" id="spec" name="spec" readonly="readonly"  maxlength="32" class="span7"/>
			</div>
		</div>
		
		<div class="control-group span6 minWidth">
			<label class="control-label">批准文号：</label>
			<div class="controls">
				<input type="text"  id="customBillNo" readonly="readonly" name="customBillNo" maxlength="32" class="span7"/>
				
			</div>
		</div>
	</div>
	
	<div class="row-fluid">
		<div class="control-group span6 minWidth">
			<label class="control-label">批号：</label>
			<div class="controls">
				<input type="text" id="batchno" name="batchno"   maxlength="32" class="span7  required" onblur="checkBatchno()"/>
				<label id="ll" style="color:red"></label>
			</div>
		</div>
		
		<div class="control-group span6 minWidth">
			<label class="control-label">确认批号：</label>
			<div class="controls">
				<input type="text" id="batchno1" name="batchno1"  onblur="check(this)" maxlength="32" class="span7  required"/>
				<label id="la" style="color:red"></label>
			</div>
		</div>
	</div>


	<div class="row-fluid">
		<div class="control-group span6 minWidth">
			<label class="control-label"><abbr title="(暂时不需要录入)">亚批号：</abbr></label>
			<div class="controls">
				<input type="text" id="batchno2" name="batchno2"   maxlength="32" class="span7 "/>
			</div>
		</div>
		
		<div class="control-group span6 minWidth">
			<label class="control-label">有效日期至：</label>
			<div class="controls">
					<input id="outBoundDate" name="outBoundDate" type="text" maxlength="20" class="span7 Wdate required"
					value=""
					onclick="WdatePicker({dateFmt:'yyyy-MM-dd',isShowClear:true});"/>
			</div>
		</div>
	</div>	
	
	<div class="row-fluid">
		<div class="control-group span6 minWidth">
			<label class="control-label">剂型：</label>
			<div class="controls">
				
				<input type="text" id="doseType" name="doseType"  readonly="readonly"  maxlength="32" class="span7"/>
			</div>
		</div>
		
		<div class="control-group span6 minWidth">
			<label class="control-label">大包装(支(粒)/箱)：</label>
			<div class="controls">
				
				<input type="text" id="largePackage" name="largePackage" readonly="readonly"  maxlength="32" class="span7"/>
			</div>
		</div>
	</div>
	<div class="row-fluid">	
		<div class="control-group span6 minWidth">
			<label class="control-label">剂量：</label>
			<div class="controls">
				
				<input type="text" id="dose" name="dose" readonly="readonly"  maxlength="32" class="span7"/>
			</div>
		</div>
		<div class="control-group span6 minWidth">
			<label class="control-label">容器类型：</label>
			<div class="controls">
				<input type="text" id="containerTypeName" name="containerTypeName" readonly="readonly"  maxlength="255" class="span7"/>
			</div>
		</div>
	</div>
	<div class="row-fluid">	
		<div class="control-group span6 minWidth">
			<label class="control-label">接种途径：</label>
			<div class="controls">
				<%-- <form:select path="inoculation" id="inoculation" class="span7">
					<form:option value="" label="--请选择--"/>
					<c:forEach items="${fns:getDictList('inoculation_route')}" var="dict">
						<option value="${dict.value}">${dict.label}</option>
					</c:forEach>
				</form:select> --%>
				<select id="inoculation" name="inoculation" class="span7">
					<option value="">-请选择-</option>
					<c:forEach items="${fns:getDictList('inoculation_route')}" var="dict">
						<option value="${dict.value}">${dict.label}</option>
					</c:forEach>
				</select>
			</div>
		</div>
		<div class="control-group span6 minWidth">
			<label class="control-label">是否为进口疫苗：</label>
			<div class="controls">
				<select id="isYes" class="span7">
				<option value="">-请选择-</option>
				<option value="1">是</option>
				<option value="0">否</option>
				</select>
		</div>
		</div>
	</div>	
	<div class="row-fluid">	
	    <div class="control-group span6 minWidth">
			<label class="control-label">批签发合格证明编号：</label>
			<div class="controls">
				<input type="text"  id="certifiCode" name="certifiCode" maxlength="32" class="span7"/>
			</div>
		</div>
		<div class="control-group span6 minWidth">
			<label class="control-label">进口通关单编号：</label>
			<div class="controls">
				<input type="text"  id="code" readonly="readonly" name="code" maxlength="32" class="span7"/>
			</div>
		</div>
	</div>	
		<div class="control-group" style="font-size:12px;color:red;line-height:10px">
		  <p>*按照新工作规规范，规定批号规则：批号中不允许出现 "("、")"、"~"、"," 等字符，正确格式如 "201108043-1" 或者 "20110a043"。</p>
		  <p>批签发中批号格式处理方式如下：</p>
          <p>1) 格式如 "201204011(1 - 3)" , 须拆分成"201204011-1","201204011-2","201204011-3" 三种批号新增</p>
          <p>2) 格式如 "201204011(1 ~ 3)" , 须拆分成"201204011-1","201204011-2","201204011-3" 三种批号新增</p>
          <p>3) 格式如 "201204011(-1 - -3)" , 须拆分成"201204011-1","201204011-2","201204011-3" 三种批号新增</p>
          <p>4) 格式如 "201204011(-1 ~ -3)" , 须拆分成"201204011-1","201204011-2","201204011-3" 三种批号新增</p>
          <p>5) 格式如 "201204011(1 , 2 , 3)" , 须拆分成"201204011-1","201204011-2","201204011-3" 三种批号新增</p>
          <p>6) 格式如 "201204011(-1, -2, -3)" , 须拆分成"201204011-1","201204011-2","201204011-3" 三种批号新增</p>
          <p>7) 格式如 "201204011-(1 , 2 , 3)" , 须拆分成"201204011-1","201204011-2","201204011-3" 三种批号新增</p>
          <p>8) 格式如 "201204011-(1 - 3)" , 须拆分成"201204011-1","201204011-2","201204011-3" 三种批号新增</p>
          <p>9) 格式如 "201204011-(1 ~ 3)" , 须拆分成"201204011-1","201204011-2","201204011-3" 三种批号新增</p>
          <p>*注：提交时批号将会转成小写 
		</div>
		
		<div class="form-actions">
			<%-- <shiro:hasPermission name="vaccineinfo:bsVaccineInfo:edit"> --%>
			<%-- </shiro:hasPermission> --%>
			<input id="btnSubmit" class="btn btn-primary" type="button"  onclick="save()" value="保 存"/>&nbsp;&nbsp;
			<input id="btnReset" class="btn btn-primary" type="button" onclick="rese()" value="重置"/>&nbsp;&nbsp;
			<input id="btnCancel" class="btn" type="button" value="返 回" onclick="history.go(-1)"/>&nbsp;&nbsp;
			<input id="btnClose" class="btn btn-primary" type="button" onclick="closeIframe()" value="关闭"/>
		</div>
</div>
	</form>
</body>
</html>